﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace VRacer.Bonus
{
    public static class BonusFactory
    {
        static private List<Type> _bonuses = new List<Type>();

        static BonusFactory()
        {
            Add(typeof(Bonus.MovesDownBonus));
            Add(typeof(Bonus.MovesUpBonus));
            Add(typeof(Bonus.SpeedDownBonus));
            Add(typeof(Bonus.SpeedUpBonus));
        }

        /// <summary>
        /// Dodaj nowy typ bonusu
        /// </summary>
        /// <param name="packetType">Type of the packet.</param>
        public static void Add(Type packetType)
        {
            _bonuses.Add(packetType);
        }

        /// <summary>
        /// Pobierz nowy bonus
        /// </summary>
        /// <param name="track">The track.</param>
        /// <returns></returns>
        public static IBonus Get(Track track)
        {
            var random = new Random((int)DateTime.Now.Ticks);
            var bonusType = _bonuses[random.Next(_bonuses.Count)];

            var bonus = (IBonus)bonusType.GetConstructor(new Type[] { }).Invoke(null);
            bonus.Position = new Point(random.Next(50), random.Next(50));
            return bonus;
        }
    }
}
